home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / CONVMPG3.ZIP / CMPEG.DOC < prev    next >
Text File  |  1993-06-28  |  18KB  |  485 lines

  1.  
  2.                               CMPEG V1.0
  3.  
  4.                           MPEG Encoder for PC
  5.  
  6.                            by Stefan Eckart
  7.  
  8.                                June 1993
  9.  
  10.  
  11.     CMPEG converts a series of images into an MPEG sequence. MPEG is a
  12.     compressed (typically by a factor of 30 to 60) standardized storage
  13.     format for video. The files compressed by CMPEG can be played by
  14.     several publicly available MPEG decoders (see Appendix A).
  15.  
  16.  
  17. 1. Features
  18. ===========
  19.  
  20.  - input formats (detected automatically):
  21.  
  22.      .PPM (PBMPLUS),
  23.      .TGA (Targa 16/24 Bit)
  24.      .RAW (Image Alchemy Raw Format)
  25.  
  26.  - image size up to about 512x320 (with 640 KB RAM)
  27.  
  28.  - generates 'real' MPEG sequences containing I,P and B frames
  29.  
  30.  - can also produce files playable by Xing software decoders
  31.  
  32.  - runs under DOS / 640KB / 8086 (no '386 or Windows required)
  33.  
  34.  - many coding parameters under user control
  35.  
  36.  - loadable quantization matrices
  37.  
  38.  - choice between several motion estimation algorithms and matching
  39.    criteria
  40.  
  41.  
  42. This program is copyrighted (C) Stefan Eckart, 1993. You can use, copy
  43. and distribute this program at no charge but you may not modify or sell
  44. it. I don't take any responsibility regarding its fitness, usefulness
  45. etc. (#include <your_favourite_disclaimer>). Comments, bug reports,
  46. questions to:
  47.  
  48.   Stefan Eckart
  49.   Kagerstr. 4
  50.   D-81669 Muenchen
  51.   Germany
  52.  
  53.   email: stefan@lis.e-technik.tu-muenchen.de
  54.  
  55. Any feedback is welcome.
  56.  
  57.  
  58. 2. Introduction
  59. ===============
  60.  
  61. CMPEG converts a sequence of images into MPEG format. MPEG is a standard
  62. format for compressed storage of video (and audio), similar in concept
  63. to JPEG for individual images. It, however, provides higher compression
  64. by exploiting the similarity of consecutive images of a sequence, so
  65. called interframe coding. As with JPEG, the compression factor depends
  66. on the source material and the desired quality of the coded sequence. A
  67. compression to less than 5% of the original material is not uncommon. It
  68. is thus a convenient method to keep the heavy storage requirements of
  69. ray-traced or digitized sequences under control. The compressed
  70. sequences can later be played back by either decompressing them in
  71. real-time or by decoding them to an uncompressed intermediate format.
  72. Real-time decoding is only possible for rather small image sizes,
  73. otherwise the frame rate becomes too low. Some players/decoders are
  74. mentioned in appendix A.
  75.  
  76.  
  77. 3. Usage
  78. ========
  79.  
  80.     cmpeg [options] [intra.mat] [inter.mat] ctlfile framelist output.mpg
  81.  
  82. intra.mat  a textfile defining the quantization matrix for
  83.            intraframe-coded data (optional)
  84.  
  85. inter.mat  a textfile defining the quantization matrix for
  86.            interframe-coded data (optional)
  87.  
  88. ctlfile    a textfile specifying coding parameters
  89.  
  90. framelist  either a textfile containing a list of image filenames or
  91.            a template string in C 'printf' format (e.g. sample%d.tga)
  92.  
  93. output.mpg the MPEG file to be generated
  94.  
  95.  
  96. Options:
  97.  
  98.   -vn  determines textual output produced during encoding
  99.        n=0: none (default)
  100.        n=1: summaries only
  101.        n=2: detailed information (voluminous and cryptic, for debugging)
  102.   -dn  selects cost function to be minimized by block-matching
  103.        n=0: sum of difference magnitudes (Manhattan distance, default)
  104.        n=1: sum of squared differences (Euclidian distance)
  105.   -m0  selects logarithmic block-matching
  106.   -m1  selects full-search block-matching
  107.   -tn  framelist is template starting with number n
  108.   -x   generate Xing compatible sequences (use i.ctl as ctlfile!)
  109.   -fn  set picture rate code:
  110.  
  111.        n  pictures per second
  112.       ------------------------
  113.        1  23.976
  114.        2  24
  115.        3  25
  116.        4  29.97
  117.        5  30
  118.        6  50
  119.        7  59.94
  120.        8  60
  121.  
  122. Examples:
  123.  
  124. To convert the Targa files sample0.tga, sample1.tga, ... sample7.tga
  125. into an MPEG sequence sample.mpg run CMPEG with the following command
  126. line:
  127.  
  128.   cmpeg -v1 -t0 ipb.ctl sample%d.tga sample.mpg
  129.  
  130. The -v1 option enables display of the current frame number, the
  131. number of bits for the encoded frame and the time required for encoding
  132. the frame. -t0 informs cmpeg that it should interpret the framelist
  133. parameter (sample%d.tga) as a template string and that it should start
  134. with frame 0, proceeding through all successively numbered frames found.
  135. The %d in sample%d.tga is the (C stdlib) notation for a decimal integer.
  136. ipb.ctl is one of the control files coming with CMPEG.
  137.  
  138. You could also have created a file sample.lst explicitly listing the
  139. names of the files. This is more flexible but requires some typing
  140. effort. If you want to create a forward/backward loop, for example, you
  141. would use the following sample.lst:
  142.  
  143. sample0.tga
  144. sample1.tga
  145. sample2.tga
  146. sample3.tga
  147. sample4.tga
  148. sample5.tga
  149. sample6.tga
  150. sample7.tga
  151. sample6.tga
  152. sample5.tga
  153. sample4.tga
  154. sample3.tga
  155. sample2.tga
  156. sample1.tga
  157.  
  158. and run cmpeg with modified options:
  159.  
  160.   cmpeg -v1 ipb.ctl sample.lst sample.mpg
  161.  
  162. To increase the compression factor somewhat you can switch to full
  163. search block matching (-m1) and mean square error criterion (-d1):
  164.  
  165.   cmpeg -v1 -m1 -d1 ipb.ctl sample.lst sample.mpg
  166.  
  167. This usually doesn't pay because the gain is often only in the order
  168. of 1 or 2% and the encoding time is considerably higher.
  169.  
  170. You can also combine options:
  171.  
  172.   cmpeg -v1m1d1 ipb.ctl sample.lst sample.mpg
  173.  
  174. To create a Xing compatible file from the same Targa files, which now
  175. must be of size 160x120, call CMPEG with these options:
  176.  
  177.   cmpeg -v1 -x i.ctl sample.lst sample_x.mpg
  178.  
  179. Please note that the sample files included in the distribution
  180. (sample0.tga ... sample7.tga) are not very typical MPEG material
  181. because they can also be efficiently compressed by conventional
  182. archivers and the advantages of MPEG might not become too obvious from
  183. these examples. I just didn't want to blow up the archive by including
  184. a more realistic sequence.
  185.  
  186.  
  187. 4. File Formats
  188. ===============
  189.  
  190. CMPEG comes with three example control files: ipb.ctl, pvrg.ctl and
  191. i.ctl.
  192.  
  193. You can simply use these files without modification. ipb.ctl is for real
  194. MPEG files, whereas i.ctl has to be used to create Xing-compatible files
  195. in conjunction with the -x option. pvgr.ctl is similar to ipb.ctl and
  196. imitates the default coding parameters of the PVRG MPEG encoder (see
  197. Appendix A). Use this file if you want to compare results.
  198.  
  199. The following description of the ctlfile format assumes some familiarity
  200. with MPEG. You only need to read it if you want to create your own
  201. control files.
  202.  
  203.  
  204. 4.1 Ctlfile
  205. ===========
  206.  
  207. MPEG leaves many degrees of freedom of how to encode a sequence. Some of
  208. these choices are built into CMPEG (e.g. the decision criteria between
  209. different block types), some are selectable by options (algorithms and
  210. cost functions for determining the motion vectors) and some (those which
  211. may differ from frame to frame) are defined through ctlfile.
  212.  
  213. MPEG divides a sequence into groups of pictures, containing an arbitrary
  214. amount of pictures (but at least one). Each line in the ctlfile
  215. corresponds to exactly one frame in each group of pictures. The first
  216. character of this line determines the frame type: I, P or B. I frames,
  217. or intracoded frames, are self contained, they don't depend on the
  218. content of other frames. P frames, or predicted frames, depend on the
  219. previous I or P frame, only the difference between the predicted and the
  220. actual content is stored. B frames, or bidirectionally predicted frames
  221. or interpolated frames, depend on both a previous and a subsequent
  222. frame.
  223.  
  224. There are some rules, restricting the choice of frame type:
  225.  
  226. - the first non-B frame must be of type I
  227. - the last frame must be of type I or P
  228.  
  229. There are also two additional rules imposed by the implementation:
  230.  
  231. - no more than eight consecutive B frames
  232. - not more than 32 frames in total per group of pictures
  233.  
  234. The list is repeated as often as necessary to code all frames. Thus the
  235. list can be much shorter than the sequence itself. The simplest list is
  236. just one I frame, which produces a sequence of I frames only. This is
  237. the mode required for Xing compatible files. Leading B frame entries are
  238. skipped for the first group of pictures, because there is no previous I
  239. or P frame available for interpolation. The lines are in display order,
  240. not in decoding order.
  241.  
  242. The example ctlfile ipb.mpg defines the following pattern:
  243.  
  244. bbibbpbbpbbp
  245.  
  246. The generated MPEG stream will look like (in decoding order):
  247.  
  248. ipbbpbbpbb ibbpbbpbbpbb ibbpbbpbbpbb ...
  249.  
  250. or in display order:
  251.  
  252. ibbpbbpbbp bbibbpbbpbbp bbibbpbbpbbp ...
  253.  
  254.  
  255. Remark: Decoding order is the order in which the frames are transmitted
  256.         which differs from display order in that B frames are
  257.         transmitted after the frames on which they depend.
  258.  
  259.  
  260. The type character is followed by one to four parameters, depending on
  261. the type:
  262.  
  263. I quant
  264. P quant forward_r_size full_pel_forward
  265. B quant forward_r_size full_pel_forward backward_r_size full_pel_backw.
  266.  
  267. quant determines how fine or coarse the image information is to be
  268. quantized. The larger quant is, the larger are the quantization steps
  269. and coding noise increases. The range of allowed values is 1 to 31.
  270.  
  271. The other parameters determine the range and accuracy of the motion
  272. vectors which represent the relative position from which a particular
  273. block of the current frame is predicted. forward_r_size and
  274. backward_r_size are integers between 0 and 6 (inclusive), restricting
  275. the length of the motion vectors according to the following table:
  276.  
  277.   r_size     range
  278.   -------------------
  279.   0       -7.5..+7.5
  280.   1      -15.5..15.5
  281.   2      -31.5..31.5
  282.   3      -63.5..63.5
  283.   4     -127.5..127.5
  284.   5     -255.5..255.5
  285.   6     -511.5..511.5
  286.  
  287. If the full_pel flags are set to one, the ranges double and half pel
  288. motions are excluded. This speeds up decoding somewhat at the expense of
  289. a higher bit-rate.
  290.  
  291.  
  292. 4.2 Intra.mat and Inter.mat
  293. ===========================
  294.  
  295. MPEG allows the use of quantization matrices different from the default
  296. ones defined in the standard. In this manner the quantization noise can
  297. be tailored to the particular application. CMPEG can read non-default
  298. matrices from the files intra.mat and inter.mat. Both files have to
  299. contain a list of 64 integers each in the range 1 to 255 (inclusive).
  300. The integers must be separated by white space (space, tab, newline). If
  301. not specified, the matrices default to:
  302.  
  303. intra.mat:
  304.  
  305.  8 16 19 22 26 27 29 34
  306. 16 16 22 24 27 29 34 37
  307. 19 22 26 27 29 34 34 38
  308. 22 22 26 27 29 34 37 40
  309. 22 26 27 29 32 35 40 48
  310. 26 27 29 32 35 40 48 58
  311. 26 27 29 34 38 46 56 69
  312. 27 29 35 38 46 56 69 83
  313.  
  314. inter.mat:
  315.  
  316. 16 16 16 16 16 16 16 16
  317. 16 16 16 16 16 16 16 16
  318. 16 16 16 16 16 16 16 16
  319. 16 16 16 16 16 16 16 16
  320. 16 16 16 16 16 16 16 16
  321. 16 16 16 16 16 16 16 16
  322. 16 16 16 16 16 16 16 16
  323. 16 16 16 16 16 16 16 16
  324.  
  325. inter.mat can be specified only if intra.mat is specified also.
  326.  
  327. It is neither necessary nor recommended to include the default matrices
  328. explicitly, it merely increases the size of the MPEG file by 64 or 128
  329. bytes.
  330.  
  331.  
  332. 4.3 Infile
  333. ==========
  334.  
  335. This textfile lists the names of the images to be coded in display
  336. order. Each line should contain exactly one filename. All specified
  337. image files have to be of the same type and size.
  338.  
  339. In conjunction with the -t parameter, infile is interpreted as a
  340. template string in C library syntax. This template string has to contain
  341. exactly one % character at the position of the frame number field in the
  342. filenames followed by one or more figures and a 'd'. Here is a list of
  343. examples:
  344.  
  345.   infile       frames
  346.   ------------------------------------------------------------
  347.   f%d.tga   -> f0.tga,   f1.tga,   ... f9.tga,   f10.tga,  ...
  348.   f.%02d    -> f.00,     f.01,         f.09,     f.10,,    ...
  349.   f%03d.tga -> f000.tga, f001.tga, ... f009.tga, f010.tga, ...
  350.  
  351. The 03 in the last example stands for: field width 3, zero padded from
  352. the left. You could also use octal or hexadecimal numbering (o and x
  353. instead of d).
  354.  
  355.  
  356. 4.4 Image Files
  357. ===============
  358.  
  359. MPEG works best for 24 bit TrueColor images. CMPEG uses Targa (Targa and
  360. .TGA are trademarks of Truevision Inc.) format files (usually identified
  361. by a .TGA suffix). Both top-down and bottom-up scan order is supported.
  362. Run-length encoded files are not supported. The files can have a
  363. resolution of 24 bit or 15 bit per pixel. Keep in mind that a 24 bit
  364. representation of a sequence usually yields a smaller MPEG file than a
  365. 15 bit representation of the same sequence. You should use 15 bit only
  366. when your source material doesn't have a higher resolution or if you run
  367. out of space otherwise (24 bit Targa files are 50% larger than 15 bit
  368. files).
  369.  
  370. CMPEG also reads the Portable Bitmap Format of Jef Poskanzers PBMPLUS
  371. package (see Appendix A). Only the raw PPM format with 256 levels is
  372. supported. Another format the encoder accepts is the Raw format used by
  373. the shareware program Image Alchemy (see Appendix A) as intermediate
  374. format. These formats were chosen because PBMPLUS and Image Alchemy
  375. cover most image formats you will ever have as input and it is generally
  376. faster to convert into the format used by the conversion programs
  377. internally than into a different format, like Targa.
  378.  
  379. The file type and size is determined automatically from the first file
  380. listed in infile. All files of a sequence have to be of the same type
  381. and size.
  382.  
  383. If your source material is in a different format (e.g TIFF, JPEG, GIF)
  384. you have to convert it first to one of the above formats by using
  385. conversion programs like PBMPLUS or Image Alchemy.
  386.  
  387.  
  388. 5. Technical Information
  389. ========================
  390.  
  391. A major design goal for CMPEG was to keep it small enough to permit
  392. coding of reasonable sized files on a 640 KB '286 PC (AT) without a need
  393. for intermediate storage files. During encoding of a bidirectionally
  394. predicted image, two reference images have to be kept in memory, which
  395. limits maximum image size to about 512x320. This includes CIF format
  396. (352x288).
  397.  
  398. A Xing compatible mode was implemented which creates files that can be
  399. played on Xing MPEG players. These players are extremely fast but they
  400. are restricted to a limited subset of valid MPEG streams. Since I don't
  401. have information what exactly the requirements are for Xing
  402. compatibility, the program just imitates some but not all of the
  403. peculiarities found in files produced with Xing encoders:
  404.  
  405. - I-frames only
  406. - only one group_of_pictures header (doesn't seem to be required but
  407.   reduces filesize)
  408. - some additional optional fields (user data / extension data) which are
  409.   required by the decoder, probably for alignment purposes only
  410. - temporal_reference starting with 1 instead of 0
  411.   (this is not imitated because it is a violation of the MPEG standard
  412.   and is not required by the decoder anyway)
  413.  
  414. The program was compiled into 8086 code. This makes it a bit slower than
  415. it could be on a '386/'486. It is however still nearly twice as fast as
  416. the PVRG code compiled with GNU GCC.
  417.  
  418.  
  419. 5. Known Bugs
  420. =============
  421.  
  422.  - variable bitrate streams only (no buffer feedback control)
  423.  - constrained_parameters_flag is always set irrespective of the actual
  424.    coding parameters
  425.  
  426.  
  427. 6. Further Reading
  428. ==================
  429.  
  430. 1. Coding of moving pictures and associated audio for digital storage
  431.    media up to about 1,5 Mbit/s, Draft International Standard ISO/IEC
  432.    DIS 11172, 1992.
  433.  
  434. 2. Frequently Asked Questions (FAQ) of the alt.binaries.pictures
  435.    newsgroup: contains an introduction to MPEG.
  436.  
  437. 3. Documentation of the PVRG MPEG software: a thorough overview
  438.    covering many aspects of MPEG
  439.  
  440.  
  441. Appendix A: Related Software
  442. ============================
  443.  
  444. This list is probably incomplete, but it's all I'm aware of. Of course
  445. there are programs for other systems as well (Mac, Amiga etc.).
  446.  
  447. dmpeg*.zip     Offline MPEG decoder, written by me. Available from
  448.                ftp.rahul.net:/pub/bryanw/mpeg/...
  449.  
  450. mpeg_play      MPEG Video Software Decoder (Version 2.0; Jan 27, 1993)
  451.                Authors: Lawrence A. Rowe, Ketan Patel, and Brian Smith
  452.                Computer Science Division-EECS, Univ. of Calif. at
  453.                Berkeley
  454.                toe.cs.berkeley.edu:/pub/multimedia/mpeg/mpeg-2.0.tar.Z
  455.  
  456. mpegwin        Online port of mpeg_play for MS-Windows
  457.                by: Michael Simmons, msimmons@ecel.uwa.edu.au
  458.                toe.cs.berkeley.edu:/pub/multimedia/mpeg/Ports/mpegw*
  459.                (HiColor & TrueColor support, Shareware)
  460.  
  461. mplay.exe,
  462. mpeg.exe       DOS MPEG players from Xing Technologies
  463.                (very high speed, but decodes only a small subset of the
  464.                 MPEG standard)
  465.  
  466. MPEGv1.1/1.2alpha
  467.                MPEG Software Encoder/Decoder
  468.                Authors: Portable Video Research Group (PVRG)
  469.                havefun.stanford.edu:/pub/mpeg/MPEGv*.tar.Z
  470.  
  471. mpgcodec       PVRG encoder/decoder for PC compiled with GNU gcc
  472.                ('386 required)
  473.                posted in alt.binaries.pictures.utilities
  474.  
  475. PBMPLUS        Portable Bit Map file conversion utilities
  476.                Author: Jef Poskanzer
  477.                garbo.uwasa.fi:/pc/graphics/pbmplus.zoo
  478.  
  479. Image Alchemy  Shareware file conversion program
  480.                Author: Handmade Software Inc.
  481.                wuarchive.wustl.edu:/msdos/graphics/alch*
  482.  
  483. --
  484. Stefan Eckart, stefan@lis.e-technik.tu-muenchen.de, June 1993.
  485.